package com.kadron.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.kadron.base.KVBase;
import com.kadron.enumeration.OrderStatus;
import com.sun.istack.internal.NotNull;

@Entity
@Table(name = "k_order")
public class Order extends KVBase implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3176032945392008138L;

	private User user;
	private Currency currency;
	private OrderStatus status = OrderStatus.ORDERED;
	private String comment;
	private long bonusKadrons;
	private String reference;
	private String address;

	private Order() {
		super();
	}

	public Order(User user, Currency currency) {
		this();
		this.user = user;
		this.currency = currency;
	}

	@ManyToOne
	@NotNull
	@JoinColumn(name = "user_id", updatable = false)
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@ManyToOne
	@JoinColumn(name = "currency_id", updatable = false)
	public Currency getCurrency() {
		return currency;
	}

	public void setCurrency(Currency currency) {
		this.currency = currency;
	}

	@Enumerated(EnumType.ORDINAL)
	@Column(name = "status")
	public OrderStatus getStatus() {
		return status;
	}

	public void setStatus(OrderStatus status) {
		this.status = status;
	}

	@Column(name = "comment", columnDefinition = "TEXT")
	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	@Column(name = "bonus_kadrons", updatable = false, nullable = false)
	public long getBonusKadrons() {
		return bonusKadrons;
	}
	
	public void setBonusKadrons(long bonusKadrons) {
		this.bonusKadrons = bonusKadrons;
	}
	
	@Column(name = "reference")
	public String getReference() {
		return reference;
	}

	public void setReference(String reference) {
		this.reference = reference;
	}

	@Column(name = "address")
	public String getAddress() {
		return address;
	}
	
	public void setAddress(String address) {
		this.address = address;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Order other = (Order) obj;
		if (id != other.id)
			return false;
		return true;
	}


}
